package com.cloud.client.cloudclient.controller;

import com.cloud.client.cloudclient.service.ClientService;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(value = "/client1")
public class ClientController {

	@Autowired
	private ClientService clientService;

	@RequestMapping(value = "/hystrix",method = RequestMethod.GET)
	@HystrixCommand(fallbackMethod = "getfallBack")
	public Map<String,Object> getUserInfo(){


		String result =clientService.getClientServer();
		System.out.println(result);
		Map<String,Object> map=new HashMap<>();
		map.put("code",result);
		return  map;
	}

	//熔断的方法必须为public不然没法进行反向代理（坑点，定义私有会出现所有注入的bean都为null）
	public Map<String,Object> getfallBack(){
		Map<String,Object> map=new HashMap<>();
		map.put("code","出错了");
		return  map;
	}
}
